

//预加载
var loader = new resLoader({
	resources : [
		'img/music-bg.png','img/icon-music.png','img/bg.png','img/icon-next.png',
		'img/firstpage/firt-title.png','img/firstpage/first-text-top.png','img/firstpage/first2.png','img/firstpage/line.png','img/firstpage/icon-place.png','img/firstpage/first1.png',
		'img/firstpage/first3.png','img/firstpage/first-text-bottom.png','img/firstpage/first4.png','img/firstpage/first5.png',
		'img/secondpage/second-header.png','img/secondpage/second-title.png','img/secondpage/second-table.png','img/secondpage/second1.png','img/secondpage/second2.png','img/secondpage/second3.png',
		'img/secondpage/second-statue.png','img/secondpage/second-bottom.png','img/secondpage/second-text.png','img/secondpage/second-plane.png',
		'img/thirdpage/third-header.png','img/thirdpage/third-title.png','img/thirdpage/third-center.png','img/thirdpage/text1.png','img/thirdpage/text2.png','img/thirdpage/text3.png','img/thirdpage/third-statue.png',
		'img/thirdpage/third-bottom.png','img/thirdpage/third3.png','img/thirdpage/third-text.png',
		'img/fourthpage/fourth-header.png','img/fourthpage/fourth-title.png','img/fourthpage/fourth-center.png','img/fourthpage/text1.png','img/fourthpage/text2.png','img/fourthpage/text3.png','img/fourthpage/text4.png',
		'img/fourthpage/text5.png','img/fourthpage/fourth-statue.png','img/fourthpage/fourth-bottom.png',
		'img/fifthpage/fifth-header.png','img/fifthpage/fifth-title.png','img/fifthpage/fifth-center.png','img/fifthpage/text1.png','img/fifthpage/text2.png','img/fifthpage/text3.png','img/fifthpage/fifth-plane.png',
		'img/fifthpage/fifth-text.png','img/fifthpage/fifth-bottom.png',
		'img/sixthpage/sixth-header.png','img/sixthpage/sixth-title.png','img/sixthpage/sixth-text.png','img/sixthpage/sixth-plane.png','img/sixthpage/sixth-statue.png','img/sixthpage/sixth-bottom1.png','img/sixthpage/sixth-bottom2.png',
		'img/seventhpage/seventh-header.png','img/seventhpage/seventh-title.png','img/seventhpage/seventh-center.png','img/seventhpage/seventh-center1.png','img/seventhpage/seventh-statue.png','img/seventhpage/seventh-plane.png',
		'img/seventhpage/seventh-text.png','img/seventhpage/seventh-bottom.png',
		'img/eighthpage/eighth-header.png','img/eighthpage/eighth-bg.png','img/eighthpage/playbtn.png','img/eighthpage/eighth-center.png','img/eighthpage/eighth-statue.png',
		'img/eighthpage/eighth-plane.png','img/eighthpage/logo.png','img/eighthpage/dian.png','img/eighthpage/eighth-bottom.png'
	],
	onstart : function(total){
		
	},
	onProgress : function(current,total){
		var percent = parseInt(current/total*100);
		$('.loading-percent').text(percent+'%');
	},
	onComplete : function(total){
		$('.loading-wrapper').css('display','none');
		$('.page').css('opacity','1');
		$('.music-wrapper').css('opacity','1');
		musicplay();
		swiper();
	}
});

//先加载loading页资源
var loaderLoading = new resLoader({
	resources : [
		'img/loadingbg.png','img/loading.png'
	],
	onstart : function(total){},
	onProgress : function(current,total){},
	onComplete : function(total){
		$('.loading-wrapper').css('opacity','1');
		loader.start();
	}
});
loaderLoading.start();


var page = null,
	pageArr = ['firstpage', 'secondpage', 'thirdpage', 'fourthpage', 'fifthpage', 'sixthpage', 'seventhpage', 'eighthpage'];
location.hash = page = pageArr[0];
var swiper = function(){
	var mySwiper = new Swiper('.swiper-container', {
		speed:500,
		initialSlide : 0,
		direction : 'vertical',
		onInit: function(swiper){ 
	      	swiperAnimateCache(swiper);    //隐藏动画元素 
	      	swiperAnimate(swiper);         //初始化完成开始动画
	    }, 
	    onSlideChangeEnd: function(swiper){ 
	        swiperAnimate(swiper);           //每个slide切换结束时也运行当前slide动画
	        if(swiper.activeIndex !== 3){
	        	$('#piecanvas').remove();
	        }
	        if(swiper.activeIndex === 3){
	        	$('.page-four .page-center').append('<div class="center-table textcenter" id="piecanvas"></div>');
	        	var timer =setTimeout(function(){
	        		canvaspie();
	        	},500)
	        }
	        page = pageArr[swiper.activeIndex];
			location.hash = page;
			wxshare();
			return page;
	    } 
	});
}




//1.音乐播放
var $music = $('.music-wrapper'),
	$icon_music = $('.music-wrapper .icon-music'),
	$audio = $('.music-wrapper audio');
var musicOff = false;
var musicplay = function(){
	$audio.trigger('play');
	//解决微信无法播放音乐问题
	document.addEventListener("WeixinJSBridgeReady", function() {
		$audio.trigger('play');
	}, false);
	$audio.attr('autoplay','autoplay');
	$icon_music.css('animation','music 6s infinite linear');
}
$music.click(function(){
	//1.1播放
	if(musicOff){
		$audio.trigger('play');
		$icon_music.css('animation','music 6s infinite linear');
		musicOff = false;
		return false;
	}
	
	//1.2暂停
	$audio.trigger('pause');
	$icon_music.css('animation','none');
	musicOff = true;
});





//2.分享按钮
var sharebtn = function(){
	var $share_view =$('.share-view');
	$('#sharebtn').click(function(){
		$share_view.fadeIn();
	});
	$share_view.click(function(){
		$(this).fadeOut();
	});
}
sharebtn();






//3.视频播放
var $playbtn = $('.playbtn'),
	$video = $('#video');
$playbtn.click(function(){
	$(this).css('display','none');
	$video.trigger('play');
	$video.attr('controls','controls');
	
	//关闭音乐
	$music.trigger('click');
});

document.getElementById('video').addEventListener('paused',function(){
	$music.trigger('click');
});







wx.ready(function(){
	wxshare();
});
wx.error(function(res){
    console.log(res); 
});
function wxshare(){
	var title = '助力中国制造更强大，2018请为工业设计打Call',
	    ptext = '工业设计师们为中国制造的崛起默默奉献多年，2018是时候要锋芒毕露了！为中国有更好的产品，也为自己心中的坚持！';
	
	wx.onMenuShareTimeline({
	    title: title,   // 分享标题
	    link: 'http://x1.t1.laisj.com/H5/laisjendofyearH5/', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
	    imgUrl: 'http://x1.t1.laisj.com/H5/laisjendofyearH5/img/sharepng.jpeg', // 分享图标
	    success: function () { 
	        // 用户确认分享后执行的回调函数
	        console.log('successShareTimeline');
	        _hmt.push(['_trackEvent', 'sharelaisjH5', 'ShareTimeline', page,0]);
	    },
	    cancel: function () { 
	        // 用户取消分享后执行的回调函数
	        _hmt.push(['_trackEvent', 'sharelaisjH5', 'ShareTimeline', page,2]);
	    }
	});
	//分享给朋友
	wx.onMenuShareAppMessage({
	    title: title, // 分享标题
	    desc: ptext, // 分享描述
	    link: 'http://x1.t1.laisj.com/H5/laisjendofyearH5/', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
	    imgUrl: 'http://x1.t1.laisj.com/H5/laisjendofyearH5/img/sharepng.jpeg', // 分享图标
	    type: 'link', // 分享类型,music、video或link，不填默认为link
	    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
	    success: function () { 
	        // 用户确认分享后执行的回调函数
	        console.log('successShareAppMessage');
	        _hmt.push(['_trackEvent', 'sharelaisjH5', 'ShareAppMessage', page,0]);
	    },
	    cancel: function () { 
	        // 用户取消分享后执行的回调函数
	        _hmt.push(['_trackEvent', 'sharelaisjH5', 'ShareAppMessage', page,2]);
	    }
	});
}







//5.

var canvaspie = function(){
	var myChart = echarts.init(document.getElementById('piecanvas'));
	var option = {
	    color: [
	        '#ee9738','#facd89','#fff799','#ffd301','#f8b551'
	    ],
	    textStyle:{
	        color:'#000000',
	        fontSize:'20px'
	    },
	    series : [
	        {
	            // name: '访问来源',
	            type: 'pie',
	            radius : '70%',
	            silent: true,
	            center: ['50%', '50%'],
	            selectedOffset:'3',
	            labelLine:{
	                normal:{
	                    lineStyle:{
	                        color:'#ffd301'
	                    },
	                }
	            },
	            data:[
	                {value:38, name:'家电类  38%'},
	                {value:32, name:'电子产品  32%'},
	                {value:12, name:'家居产品  12%'},
	                {value:11, name:'灯饰类 11%'},
	                {value:7, name:'其他  7%'}
	            ],
	            
	        }
	    ]
	};
	myChart.setOption(option);
}